package main

func main() {

	//[1,2,2,null,3,null,3]

	root := &TreeNode{
		Val: 1,
		Left: &TreeNode{
			Val:  2,
			Left: nil,
			Right: &TreeNode{
				Val:  3,
				Left: nil,
			},
		},
		Right: &TreeNode{
			Val:  2,
			Left: nil,
			Right: &TreeNode{
				Val:  3,
				Left: nil,
			},
		},
	}
	println(isSymmetric(root))
}

func isSymmetric(root *TreeNode) bool {
	if root == nil {
		return true
	}

	var eq func(leftNode *TreeNode, rightNode *TreeNode) bool

	eq = func(leftNode *TreeNode, rightNode *TreeNode) bool {
		if leftNode == nil && rightNode == nil {
			return true
		}

		if leftNode == nil || rightNode == nil {
			return false
		}

		if leftNode.Val != rightNode.Val {
			return false
		}

		return eq(leftNode.Left, rightNode.Right) && eq(leftNode.Right, rightNode.Left)

	}

	return eq(root, root)
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}
